package com.example.service;

import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Create with Intellij idea
 * User:mingtian
 * Date:2018/11/29
 * Time:20:56
 */
public class OrderService {

    //uuid生成  应用场景,数据主键、Token    不占宽带
    //缺点:不递增、以字符串存储查询效率低、占存储空间比较大、传输较大
    public static String getUuid() {
        String uuid = UUID.randomUUID().toString().replace("-", "");
        return uuid;
    }

    public static String getOrderId() {
        //线程池
        ExecutorService executorService = Executors.newFixedThreadPool(1000);
        for (int i = 0; i < 100; i++) {
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    String uuid = UUID.randomUUID().toString().replace("-", "");
                    String sql="insert into orderNumber value('"+uuid+"');";
                    System.out.println(sql);
                }
            });

        }
        return null;
    }

    public static void main(String[] args) throws InterruptedException {

        //getOrderId();
        System.out.println(UUID.randomUUID());
        Thread.sleep(3000);
        System.out.println(UUID.randomUUID());
    }
}
